﻿<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link href="static/css/bootstrap.css" rel="stylesheet">
	<script src="static/js/jquery-1.11.1.min.js" type="text/javascript"></script>
	<script src="static/js/bootstrap.min.js"></script>
	<link href="static/css/jquery-ui.min.css" rel="stylesheet" media="screen">
	<script src="static/js/jquery-ui.min.js" type="text/javascript"></script>
	<script src="static/js/jquery-ui-i18n.js"></script>
	
	<style type="text/css">
		.div{width:90%;margin-left: auto;margin-right: auto;}
		.login{width:35%;margin-left: auto;margin-right: auto;}
	</style>
  </head>
<body>
<div class="navbar navbar-inverse div">
        <div class="container">
          <div class="navbar-header">
            <a class="navbar-brand" href="/">治具借用管理系統</a>
			{% if status=="1" %}
				<a class="navbar-brand navbar-left" id="logout" data-toggle="modal" href="/logout">{{ user }},歡迎您！</a>
				<a class="navbar-brand navbar-left" href="#" onclick=sky(1)  title="新增異動記錄">新增異動記錄</a>
				<a class="navbar-brand navbar-left" href="#" onclick=sky(2)  title="新增記錄">新增治具</a>
				<a class="navbar-brand navbar-left" href="#" onclick=sky(3)  title="查詢">查詢</a>
				<a class="navbar-brand navbar-left" href="#" onclick=sky(5)  title="查詢">用戶管理</a>
				<a class="navbar-brand navbar-left" href="#" onclick=sky(6)  title="查詢">人事資料</a>
			{% else %}
				<a class="navbar-brand" id="status" data-toggle="modal" href="#login">Login</a>
			{% end %}
          </div>
        </div>
      </div>

<br>
<div id="show">
</div>
<!-- Login-->
<div class="modal fade" id="login" tabindex="-1" role="dialog" aria-labelledby="loginmodal" aria-hidden="true">
  <div class="modal-dialog login">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="form-signin-heading">Please sign in</h4>
      </div>
      <div class="modal-body">
		   <div class="container modal-60 div">
			<input type="text" id="username" class="form-control" placeholder="User Name" required autofocus>
			<input type="password" id="password" class="form-control" placeholder="Password" required>
			<label class="checkbox">
			<input type="checkbox" value="remember-me"> Remember me
			</label>
			<button class="btn btn-lg btn-primary btn-block" type="button" id="loginpost">Sign in</button>
		</div>
      </div>
    </div>
  </div>
</div>
<!-- NEW-->
<div class="modal fade" id="new" tabindex="-1" role="dialog" aria-labelledby="NewModal" aria-hidden="true">
  <div class="modal-dialog login">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="new"><b>新增異動記錄：</b></h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		<table class="div">
			<tr><td>工號條碼:</td><td><input type="text" class="form-control" id='userid' name='userid'></td></tr>
			<tr><td>治具條碼:</td><td><input type="text" class="form-control" id='jignum'></td></tr>
			<tr><td>線別:</td><td><input type="text" class="form-control" id='line'></td></tr>
			<tr><td>用途:</td><td><input type="text" class="form-control" id='use'></td></tr>
			<tr><td>類型:</td><td><input type="radio" name="radiobutton" value="lend" checked>借出
				<input type="radio" name="radiobutton" value="return">歸還</td></tr>
			<tr><td>備註:</td><td><input type="text" class="form-control" id='remark'></td></tr>
		</table>
	    </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" id="newpost" class="btn btn-primary">提交</button>
      </div>
    </div>
  </div>
</div>
<!-- ADD-->
<div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="NewModal" aria-hidden="true">
  <div class="modal-dialog login">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="add"><b>新增治具資產：</b></h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
		<table class="div">
			<tr><td>治具條碼:</td><td><input type="text" class="form-control" id='jigid'></td></tr>
			<tr><td>治具名稱</td><td><input type="text" class="form-control" id='jigname'></td></tr>
		</table>
	    </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button type="button" id="newadd" class="btn btn-primary">提交</button>
      </div>
    </div>
  </div>
</div>
<!-- query-->
<div class="modal fade" id="query" tabindex="-1" role="dialog" aria-labelledby="NewModal" aria-hidden="true">
  <div class="modal-dialog div">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="new">查詢記錄：</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
	    <div class="table-responsive div">
		<h4 class="modal-title" id="new">可輸入治具ID或者保管人工號進行查詢，輸入*可查詢所有治具：</h4>
        <table id="main" class="table table-striped table-bordered table-hover">
		<tr>
		<td><input type="text" class="form-control" id='queryinput'></td>
		<td><button type="button" id="postquery" class="btn btn-primary">提交</button></td>
		</tr>
		</table>
		</div>
		<div id="querylist"></div>
	    </div>
      </div>
    </div>
  </div>
</div>
<!-- users-->
<div class="modal fade" id="users" tabindex="-1" role="dialog" aria-labelledby="NewModal" aria-hidden="true">
  <div class="modal-dialog login">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="new">用戶管理：</h4>
      </div>
      <div class="modal-body">
        <div class="form-group">
	    <div class="table-responsive div">
		<h4 class="modal-title" id="new">密碼修改：</h4>
        <table id="main" class="table table-striped table-bordered table-hover">
		<tr>
		<td>舊密碼：<input type="password" class="form-control" id='oldpwd'></td>
		</tr>
		<tr>
		<td>新密碼：<input type="password" class="form-control" id='newpwd1'></td>
		</tr>
		<tr>
		<td>確認輸入：<input type="password" class="form-control" id='newpwd2'></td>
		<td><button type="button" id="userpost" class="btn btn-primary">確定</button></td>
		</tr>
		</table>
		</div>
	    </div>
      </div>
    </div>
  </div>
</div>
<!-- HR-->
<div class="modal fade" id="hr" tabindex="-1" role="dialog" aria-labelledby="NewModal" aria-hidden="true">
  <div class="modal-dialog div">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title"><b>人事資料管理維護：</b></h4>
      </div>
      <div class="modal-body login">
        <div class="form-group">
		<h4 class="modal-title"><b>新增用戶資料：</b></h4>
		<table>
			<tr><td>工號:</td><td><input type="text" class="form-control" id='newid'></td></tr>
			<tr><td>姓名:</td><td><input type="text" class="form-control" id='newname'></td></tr>
			<tr><td>部門:</td><td><input type="text" class="form-control" id='neworg'></td></tr>
		</table>
	    </div>
		<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		<button type="button" id="newhr" class="btn btn-primary">提交</button>
      </div>
	  <h4 class="modal-title"><b>用戶資料：</b></h4>
      <div class="modal-footer" id="hrlist">
      </div>
    </div>
  </div>
</div>
<script>
$.datepicker.setDefaults($.datepicker.regional['zh-TW']);
$(function() {
	$("#starttime").datepicker({showButtonPanel: true,dateFormat: 'yy-mm-dd' });});
$(function() {
	$("#endtime").datepicker({showButtonPanel: true,dateFormat: 'yy-mm-dd' });});
</script>
<script type="text/javascript">
$(document).ready(function(){
	if ({{ status }}=="0") {
		$('#login').modal();
		} else {
	$.post("/",{},function(tab){$("#show").html(tab)})}
	})

$("#newadd").click(function(){
var jigid=$("#jigid").val();
var jigname=$("#jigname").val();
if (jigid=="" || jigname=="")  {alert("有必填項目為空：治具ID或者治具名稱")}
	else {
		$.post("/add",{
			jigid:jigid,
			jigname:jigname,
			},function(date){
				if (date=="0") {alert("添加成功!")} 
				else 
					{alert(date)}
				})
	}
})
$("#OK").click(function(){
	if ($("#pcname").val()== ""){
		alert("Please Input!");
	}
	else {
	$.post("adminquery",{
	  pcname:$("#pcname").val()
	},function(data){
	$("#show").html(data);
	}).error(function(){alert("請求失敗，請聯繫系統管理員！");});
	}
	})
$("#loginpost").click(
		function(){
			if($("#username").val() =="" || $("#password").val() ==""){
				alert("用戶名或密碼不能為空！");}
			else {
				if ({{ status }}=="0"){
					$("#login").modal("hide");
					$.post("login",{
						username:$("#username").val(),
						password:$("#password").val(),},
						function(user){
							if(user=="0"){alert("登錄失敗：用戶名或密碼有誤！");}
							else {location.reload();}
					
						}).error(function(){alert("請求失敗，請聯繫系統管理員！");})
				} else {alert("您已經登入，請勿重複操作！");}}
})
$("#logout").click(
	function(){
	if  (confirm("確定要登出？")){
		return true;
	}
	else {
		return false;
	}

	})

function sky(id)
{
	if ({{ status }} !="1")
		{
			alert("抱歉，您還未登陸,僅能使用查詢功能！");
			$('#login').modal();
		}
	else
		{
		if(id==1){
			$("#new").modal();
			$('#userid').focus();
			}
		if(id==2){
			$("#add").modal();
			}
		if(id==3){
			$("#query").modal();}
		if(id==6){
			$("#hr").modal();
			$.post('hr',{Request:"list"},function(data){$("#hrlist").html(data)})
			}
		if(id==5){
			$("#users").modal();
			}
		}
}

function del(type,id,jigname)
	{
	if ({{ status }} =="1"){
		var msg='確定要刪除' +jigname+ '嗎？\n注意：刪除后將無法恢復！'
		if (confirm(msg)){
			if (type=='stock'){
				$.post("del",{TYPE:'stock',delid:id},function(data){alert(data);})}
			else if (type=='hr'){
				$.post("del",{TYPE:'hr',delid:id},function(data){alert(data);})
			}
	}}
	else {
		alert("抱歉，您還未登陸，僅能使用查詢功能！");
		$('#login').modal();
		}
	}
$("#newpost").click(function(){
	var num=/^[0-9]{8}$/;
	var userid=$("#userid").val();
	var jignum=$("#jignum").val();
	var line=$("#line").val();
	var use=$("#use").val();
	var select=$('input:radio[name="radiobutton"]:checked').val();
	var remark=$("#remark").val();
	if (!num.test(userid)) {alert("工號輸入有誤！必須是8位數字!")}
	else if (jignum==""){alert("有必填項目為空！必填項：治具ID")}
	else {
		$.post("new",{
		userid:userid,
		jignum:jignum,
		line:line,
		use:use,
		select:select,
		remark:remark,
		},function(data){alert(data);
		location.reload();})
	}
	})
$("#newhr").click(function(){
var num=/^[0-9]{8}$/;
var newid=$("#newid").val();
var newname=$("#newname").val();
var neworg=$("#neworg").val();
if (!num.test(newid)) {alert("工號輸入有誤！必須是8位數字,人事資料錯誤將直接導致資料記錄出現嚴重錯誤，請務必慎重操作！！！")}
else if ($("#newname").val()=="" || $("#neworg").val()=="") {alert("有必填項目為空！人事資料錯誤將直接導致資料記錄出現嚴重錯誤，請務必慎重操作！！！")}
else {
	$.post("hr",{Request:"sub",newid:newid,newname:newname,neworg:neworg},function(data){alert(data)})
}
})

$("#postquery").click(function(){
	$.post("query",{command:$("#queryinput").val()},function(data) {$("#querylist").html(data)})
})
$("#userpost").click(function(){
	if($("#oldpwd").val()=="" || $("#newpwd1").val()=="" || $("#newpwd2").val()==""){alert("有必填項目為空！")}
	else if ($("#newpwd1").val()==$("#newpwd2").val()) {
		$.post("users",{oldpwd:$("#oldpwd").val(),newpwd:$("#newpwd1").val(),newpwd2:$("#newpwd2").val(),user:"{{ user }}"},function(data){
		if(data=="0"){alert("密碼修改成功!");location.href="logout";}
		else {alert(data)}
		})
		}
	else {alert("兩次輸入不一致！")}
})
</script>
</body>
</html>